package com.itheima.user.controller;


import com.itheima.common.enums.HttpCodeEnum;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import com.itheima.user.dto.AdPageUserDto;
import com.itheima.user.pojo.ApUserRealname;
import com.itheima.user.service.ApUserRealnameService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.itheima.core.controller.AbstractCoreController;

import java.util.Map;

/**
 * @description <p>APP实名认证信息</p>
 *
 * @version 1.0
 * @package com.itheima.user.controller
 */
@Api(value="ApUserRealnameController",tags = "APP实名认证信息")
@RestController
@RequestMapping("/auth")
public class ApUserRealnameController extends AbstractCoreController<ApUserRealname> {

    private ApUserRealnameService apUserRealnameService;

    @Autowired
    public ApUserRealnameController(ApUserRealnameService apUserRealnameService) {
        super(apUserRealnameService);
        this.apUserRealnameService=apUserRealnameService;
    }

    /**
     * 实名认证分页查询接口
     * @param adPageUserDto 接收前端传过来的查询条件数据
     * @return 返回分页查询的数据
     */
    @ApiOperation("分页查询")
    @PostMapping("/list")
    public PageResultVo authPage(@RequestBody AdPageUserDto adPageUserDto){

        return apUserRealnameService.pageList(adPageUserDto);
    }

    /**
     * 实名认证驳回请求
     * @param authMap 接收前端传过来的参数
     * @return 返回驳回请求参数
     */
    @ApiOperation("实名认证驳回")
    @PostMapping("/authFail")
    public ResultVo authFail(@RequestBody Map<String,Object> authMap){
        //调用service层的方法进行对数据库修改,判断是否修改成功
        if (apUserRealnameService.authFail(authMap)){
            return ResultVo.ok("驳回成功！");
        }
        return ResultVo.error(HttpCodeEnum.SERVER_ERROR);
    }

    @PostMapping("/authPass")
    public ResultVo authPass(@RequestBody Map<String,Object> authMap){
        //调用service层的方法进行对数据库修改,判断是否修改成功
        apUserRealnameService.authPass(authMap);
        return ResultVo.ok("审核成功！");
    }

}

